//
//  HESysMsgCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/23.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HESysMsgCell.h"
#import "HESysMsgModel.h"

@interface HESysMsgCell ()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *contentLb;

@end

@implementation HESysMsgCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = CLightGrayColor;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
 
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    warp.layer.cornerRadius = 8;
 
    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    
    // head
    
    UIView *blueLine = [UIView new];
    blueLine.backgroundColor = CNavBgColor;
    [warp addSubview:blueLine];
    
    _titleLb = [UILabel new];
    _titleLb.text = @"";
    _titleLb.font = DYBlodFont(18);
    _titleLb.numberOfLines = 0;
    [warp addSubview:_titleLb];
 
    
    UIView *headBottomLine = [UIView new];
    headBottomLine.backgroundColor = CSplitLineColor;
    [warp addSubview: headBottomLine];
    
    
    _timeLb = [UILabel new];
    _timeLb.text = @"";
    _timeLb.font = DYFont(16);
    _timeLb.textColor = CNavDargGrayColor;
    [warp addSubview: _timeLb];
 
     
    _contentLb = [UILabel new];
    _contentLb.text = @"";
    _contentLb.font = DYFont(16);
    _contentLb.textColor = CNavDargGrayColor;
    _contentLb.numberOfLines = 0;
    [warp addSubview: _contentLb];
    
    [blueLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLb);
        make.left.equalTo(warp).offset(10);
        make.width.offset(3);
        make.height.offset(20);
    }];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.left.equalTo(blueLine.mas_right).offset(10);
        make.right.equalTo(_timeLb.mas_left).offset(-10);
    }];

    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.right.equalTo(warp).offset(-15);
    }];
    [_timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
  
    [_contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).offset(15);
        make.left.equalTo(warp).offset(15);
        make.right.equalTo(warp).offset(-15);
        make.bottom.equalTo(warp).offset(-15);
    }];
      
     

     
    
//    //  footer
//    UIView *footerTopLine = [UIView new];
//    footerTopLine.backgroundColor = CSplitLineColor;
//    [warp addSubview: footerTopLine];
//    [footerTopLine mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_timeLb.mas_bottom).offset(15);
//        make.left.equalTo(warp).offset(10);
//        make.right.equalTo(warp).offset(-10);
//        make.height.offset(1);
//    }];
//
//    UILabel *checkLb = [UILabel new];
//    checkLb.text = @"立即查看";
//    checkLb.font = DYFont(16);
//    [warp addSubview: checkLb];
//
//    [checkLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(footerTopLine.mas_bottom).offset(15);
//        make.left.equalTo(warp).offset(10);
//        make.bottom.equalTo(warp.mas_bottom).offset(-15);
//    }];
//
//    UIImageView *_arrowView = [UIImageView new];
//    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
//    _arrowView.image = IMAGE_NAMED(@"go_gray");
//    [warp addSubview:_arrowView];
//
//    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(checkLb);
//        make.right.equalTo(warp).mas_offset(-15);
//        make.width.mas_offset(8);
//        make.height.mas_offset(12);
//    }];
}


- (void)configCellWithModel:(HESysMsgModel *)model {
 
    _titleLb.text = model.Ksystem_typeName;
    _timeLb.text = model.Kcreate_date;
    _contentLb.text = model.system_title;
    
    
    [self showbadge: !model.is_read];
}

- (void)showbadge:(BOOL)show {
  
    if (show) {
        [_timeLb pp_showBadge];
  
        _timeLb.badgeView.font = DYBlodFont(14);
 
        [_timeLb pp_addDotWithColor: CPriceColor];
        [_timeLb pp_setBadgeHeight: 12];
        [_timeLb pp_moveBadgeWithX: 5 Y: 0];
    }else {
        [_timeLb pp_hiddenBadge];
    }
}

@end
